package com.chanzany.interview_primary;


import java.util.Date;

class ImmutableClass {
    private Date date;
    public ImmutableClass(Date date){
//        this.date = date; //引用传递
        this.date = (Date) date.clone(); //接触引用关系
    }

    public Date getDate(){
        return date;
    }
    public void printState(){
        System.out.println(date);
    }
}

public class ImmutableClassTest{
    public static void main(String[] args) {
        Date date = new Date();
        ImmutableClass immutableClass = new ImmutableClass(date);
        immutableClass.printState(); //Tue Nov 10 14:33:50 CST 2020
        date.setMonth(4);
        immutableClass.printState(); //Sun May 10 14:33:50 CST 2020
    }
}

